package model.simulation;

import model.AbstractModel;
import model.statical.Model;
import model.dynamic.DyModel;

public class SiModel extends DyModel
{
	SiDepartment department;

	SiModel matchAuthorizedModel = null;
	SiModel matchActualModel = null;

	public SiModel()
	{
		dyNumber = number = 1;
	}

	public SiModel(Model model, SiDepartment department)
	{
		super(model);
		this.department = department;
	}

	public SiModel(SiModel authorizedModel)
	{
		this(authorizedModel, true);
	}

	public SiModel(SiModel authorizedModel, boolean added)
	{
		department = authorizedModel.department;
		if (added)
			department.siActualModels.add(this);
		this.aName = authorizedModel.getaName();
		this.bName = authorizedModel.getbName();
		this.cName = authorizedModel.getcName();
		this.dName = authorizedModel.getdName();
		this.quarter = authorizedModel.getQuarter();
		this.rankString = authorizedModel.getRankString();
		this.profession = authorizedModel.getProfession();
		this.rank = authorizedModel.getRank();
		dyNumber = number = 1;
		this.mainProfession = authorizedModel.getMainProfession();
	}

	public SiModel(AbstractModel model)
	{
		this.aName = model.getaName();
		this.bName = model.getbName();
		this.cName = model.getcName();
		this.dName = model.getdName();
		this.quarter = model.getQuarter();
		this.rankString = model.getRankString();
		this.profession = model.getProfession();
		this.rank = model.getRank();
		dyNumber = number = model.getNumber();
		this.mainProfession = model.getMainProfession();
	}

	public SiDepartment getDepartment()
	{
		return department;
	}

	public void setDepartment(SiDepartment department)
	{
		this.department = department;
	}

	void remove()
	{
		department.siActualModels.remove(this);
	}

	// 返回是否应该退役和可以按一定的概率提升
	public boolean[] changInNextYear()
	{
		int index = rank - 1;
		if (serviceAge == rankLimitAges[index] - 1
				|| rankServiceTime == rankLimitTimes[index] - 1)
			return new boolean[]{true, false};
		serviceAge++;
		rankServiceTime++;
		return new boolean[]{false, rankServiceTime > rankLeastTimes[index]};
	}

	public void initMatchAuthorizedModel(SiModel authorizedModel)
	{
		matchAuthorizedModel = authorizedModel;
		authorizedModel.matchActualModel = this;
		//		department=authorizedModel.department;
		//		department.siShiyouModels.add(this);
	}

	public void matchAuthorizedModel(SiModel authorizedModel)
	{
		if (matchAuthorizedModel != null)
			matchAuthorizedModel.matchActualModel = null;
		matchAuthorizedModel = authorizedModel;
		authorizedModel.matchActualModel = this;
	}

	public void promote(SiModel authorizedModel)
	{
		rank = authorizedModel.rank;
		rankString = authorizedModel.rankString;
		quarter = authorizedModel.quarter;
		matchAuthorizedModel(authorizedModel);
		department.siActualModels.remove(this);
		department = authorizedModel.department;
		department.siActualModels.add(this);
	}
	public void retire()
	{
		department.siActualModels.remove(this);
		if (matchAuthorizedModel != null)
			matchAuthorizedModel.matchActualModel = null;
	}
}
